﻿' Copyright (C) 2012 Artem Los, All rights reserved.
' To view the full license, goto http://softwareprotector.codeplex.com/license
Public Class main_form
    Dim skc As SKGL.SerialKeyConfiguration = New SKGL.SerialKeyConfiguration()
    Dim generate As SKGL.Generate = New SKGL.Generate(skc)
    Dim validate As SKGL.Validate = New SKGL.Validate(skc)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DateTimePicker2.Value = Today.AddDays(30)
        NumericUpDown1.Value = 30
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged

        Dim num As Integer = DateDiff(DateInterval.DayOfYear, DateTimePicker1.Value, DateTimePicker2.Value)
        If num <= 999 Then
            NumericUpDown1.Value = DateDiff(DateInterval.DayOfYear, DateTimePicker1.Value, DateTimePicker2.Value)
        Else
            DateTimePicker2.Value = DateTimePicker1.Value.AddDays(999)
            NumericUpDown1.Value = 999
        End If
    End Sub
    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        Dim num As Integer = DateDiff(DateInterval.DayOfYear, DateTimePicker1.Value, DateTimePicker2.Value)
        If num <= 999 Then
            NumericUpDown1.Value = DateDiff(DateInterval.DayOfYear, DateTimePicker1.Value, DateTimePicker2.Value)
        Else
            DateTimePicker2.Value = DateTimePicker1.Value.AddDays(999)
            NumericUpDown1.Value = 999
        End If
    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.KeyUp, NumericUpDown1.ValueChanged
        DateTimePicker2.Value = DateTimePicker1.Value.AddDays(NumericUpDown1.Value)
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox1.PasswordChar = ""
        Else
            TextBox1.PasswordChar = "*"
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        generate.secretPhase = TextBox1.Text
        skc.Features = New Boolean(7) {CheckBox2.Checked, CheckBox3.Checked, CheckBox4.Checked, CheckBox5.Checked, CheckBox6.Checked, CheckBox7.Checked, CheckBox8.Checked, CheckBox9.Checked}
        If NumericUpDown2.Value > 1 Then
            Dim frmKeys As New keys

            For i As Integer = 0 To NumericUpDown2.Value - 1
                frmKeys.TextBox1.Text &= generate.doKey(NumericUpDown1.Value, DateTimePicker1.Value) & Environment.NewLine
            Next

            frmKeys.Show()
        Else
            TextBox2.Text = generate.doKey(NumericUpDown1.Value, DateTimePicker1.Value)
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim validator As New validateCheck
        validate.Key = TextBox2.Text
        validate.secretPhase = TextBox1.Text

        If validate.IsValid Then


            validator.TextBox2.Text = TextBox2.Text
            validator.TextBox1.Text = validate.CreationDate.ToShortDateString
            validator.TextBox3.Text = validate.ExpireDate.ToShortDateString
            validator.TextBox4.Text = validate.SetTime
            validator.TextBox5.Text = validate.DaysLeft
            If validate.IsExpired Then
                validator.TextBox6.Text = "True"
                validator.TextBox6.ForeColor = Color.Red
            Else
                validator.TextBox6.Text = "False"
                validator.TextBox6.ForeColor = Color.Blue
            End If

            validator.CheckBox2.Checked = validate.Features(0)
            validator.CheckBox3.Checked = validate.Features(1)
            validator.CheckBox4.Checked = validate.Features(2)
            validator.CheckBox5.Checked = validate.Features(3)
            validator.CheckBox6.Checked = validate.Features(4)
            validator.CheckBox7.Checked = validate.Features(5)
            validator.CheckBox8.Checked = validate.Features(6)
            validator.CheckBox9.Checked = validate.Features(7)

            validator.Show()
        Else
            validator.Label2.ForeColor = Color.Red
            validator.Label2.Text = "Error"
            validator.TextBox2.Text = TextBox2.Text

            validator.Show()
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        My.Computer.Clipboard.SetText(TextBox2.Text)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Try
            Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3R59VSU8LKETW")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try
            Process.Start("http://softwareprotector.codeplex.com")
        Catch ex As Exception

        End Try
    End Sub
End Class
